package com.jerry.mingxing.ui.fashionnew;


import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import com.jerry.mingxing.R;
import com.jerry.mingxing.bean.NewBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * A simple {@link Fragment} subclass.
 */
public class FashionNewFragment extends Fragment implements FashionNewContract.View {


    private View view;
    private Activity activity;
    private List<NewBean.ResponseBean.DataBean.ItemsBean> list = new ArrayList<>();
    private FashionNewAdapter adapter;
    private GridView newGridview;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity = getActivity();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_fashion_new, container, false);


        FashionNewPresenter presenter = new FashionNewPresenter(this);
        newGridview = (GridView) view.findViewById(R.id.new_gridview);

        presenter.getData();

        return view;
    }


    @Override
    public void onResponse(NewBean nbean) {
        setAdapter(nbean);

    }

    @Override
    public void onFailure(String s) {

    }


    @OnClick(R.id.new_gridview)
    public void onClick() {
    }

    private void setAdapter(NewBean nBean) {
        list = nBean.getResponse().getData().getItems();
        adapter = new FashionNewAdapter(list, activity);

        newGridview.setAdapter(adapter);


    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
